## Dockerfile
FROM kangkang223/centos8

LABEL maintainer "chenwk.top@foxmail.com"

ENV FASTDFS_PATH=/opt/fdfs \
  FASTDFS_BASE_PATH=/var/fdfs \
  LIBFASTCOMMON_VERSION="V1.0.63" \
  LIBSERVERFRAME_VERSION="V1.1.22" \
  FASTDFS_NGINX_MODULE_VERSION="V1.23" \
  FASTDFS_VERSION="V6.09" \
  NGINX_VERSION="1.23.2" \
  PORT= \
  GROUP_NAME= \
  TRACKER_SERVER=

#create the dirs to store the files downloaded from internet
RUN mkdir -p ${FASTDFS_PATH}/libfastcommon \
  && mkdir -p ${FASTDFS_PATH}/fastdfs \
  && mkdir -p ${FASTDFS_PATH}/fastdfs-nginx-module \
  && mkdir ${FASTDFS_BASE_PATH} \
  && mkdir /nginx_conf && mkdir -p /usr/local/nginx/conf/conf.d

WORKDIR ${FASTDFS_PATH}
RUN pwd && ls -al ./

## compile the libfastcommon
RUN cd ${FASTDFS_PATH} && git clone -b ${LIBFASTCOMMON_VERSION}  https://gitee.com/fastdfs100/libfastcommon.git --depth 1 \
  && cd libfastcommon \
  && ./make.sh \
  && ./make.sh install \
  && rm -rf ${FASTDFS_PATH}/libfastcommon

RUN cd ${FASTDFS_PATH} && git clone -b ${LIBSERVERFRAME_VERSION} https://gitee.com/fastdfs100/libserverframe.git --depth 1 \
  && cd libserverframe \
  && ./make.sh \
  && ./make.sh install \
  && rm -rf ${FASTDFS_PATH}/libserverframe

## compile the fastdfs
RUN cd  ${FASTDFS_PATH} &&  git clone -b ${FASTDFS_VERSION} https://gitee.com/fastdfs100/fastdfs.git --depth 1 \
  && cd fastdfs \
  && ./make.sh \
  && ./make.sh install \
  && rm -rf ${FASTDFS_PATH}/fastdfs


RUN cd ${FASTDFS_PATH} && git clone -b ${FASTDFS_NGINX_MODULE_VERSION} https://gitee.com/fastdfs100/fastdfs-nginx-module.git --depth 1 \
  && wget https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz \
  && tar -zxf nginx-${NGINX_VERSION}.tar.gz \
  && cd nginx-${NGINX_VERSION} \
  && ./configure --prefix=/usr/local/nginx \
      --add-module=${FASTDFS_PATH}/fastdfs-nginx-module/src/ \
      --with-stream=dynamic \
  && make \
  && make install \
  && ln -s /usr/local/nginx/sbin/nginx /usr/bin/ \  
  && rm -rf ${FASTDFS_PATH}/nginx-* \
  && rm -rf ${FASTDFS_PATH}/fastdfs-nginx-module

EXPOSE 22122 23000 8080 8888 80
VOLUME ["$FASTDFS_BASE_PATH","/etc/fdfs","/usr/local/nginx/conf/conf.d"]   

COPY conf/*.* /etc/fdfs/
COPY nginx_conf/ /nginx_conf/
COPY nginx_conf/nginx.conf /usr/local/nginx/conf/

COPY entrypoint.sh /usr/bin/

#make the entrypoint.sh executable 
RUN chmod a+x /usr/bin/entrypoint.sh

WORKDIR /usr/local/nginx

ENTRYPOINT ["/usr/bin/entrypoint.sh"]
CMD ["tracker"]
